﻿//===============================================================================
// TREASURY MANAGMENT INFORMATION SYSTEMS 
// SQL Exeption Translation Class
//===============================================================================
// Copyright © EU. 2008
//===============================================================================
using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Diagnostics;
using System.Linq;
using System.Text;

namespace DAL
{
   public class SqlExeptionMessageClass
    {


        /// <summary>
        /// Translate a SqlException 
        /// </summary>
        /// <param name="ex">SqlException to be translated</param>
        /// <returns>Exeption Message</returns>
        /// The Messages Should  be  translated In Russian !
         
        public String TranslateException(SqlException ex)
        {
            
            String exeptionMessage = null;

               
                switch (ex.Number)
                {
                    case 17:
                    // 	SQL Server does not exist or access denied.
                    case 4060:
                    // Invalid Database
                    case 18456:
                        // Login Failed
                        exeptionMessage = "Login Failed";
                        break;
                    case 547:
                        // ForeignKey Violation
                        exeptionMessage = "ForeignKey Violation";
                        break;
                    case 1205:
                        // DeadLock Victim
                        exeptionMessage = "DeadLock Victim";
                        break;
                    case 2627:
                    case 2601:
                        // Unique Index/Constriant Violation
                        exeptionMessage = "Unique Index/Constriant Violation";
                        break;
                    default:
                        // throw a general DAL Exception
                        exeptionMessage = ex.Message;
                        break;
                }
            

            // return the error
            return exeptionMessage;
        }


    }
}
